
/* Define to prevent recursive inclusion --------------------------------------*/
#ifndef __DEV_C8620_H__
#define __DEV_C8620_H__
#ifdef EN_I2C_C8620

/* Includes -------------------------------------------------------------------*/
// #include "project.h"                                    // include corresponding 'h' file

/* Exported typedef -----------------------------------------------------------*/

/* Exported define ------------------------------------------------------------*/
#define C8620_BUF_SIZE 64
#define C8620_SEG_NUM 8
#define C8620_BREATH_SZIE 128

#define C8620_LUMI_FULL 0xFF
#define C8620_LUMI_HALF 0x7F
#define C8620_LUMI_OFF 0

#define C8620_MARQUEE_NUM 32

/* Control command define -----------------------------------------------------*/
/*
 * @brief  row scan command
 * @param  0x00~0x07 -> row1~row8
 */
typedef enum
{
    C8620_Row1 = 0u,
    C8620_Row2 = 1u,
    C8620_Row3 = 2u,
    C8620_Row4 = 3u,
    C8620_Row5 = 4u,
    C8620_Row6 = 5u,
    C8620_Row7 = 6u,
    C8620_Row8 = 7u
} c8620_em_cmd_row_scan_t;

/*
 * @brief  data update command
 * @param  0 -> data arbitrary update
 *         1 -> data automatic update
 */
typedef enum
{
    C8620_ArbitraryUpdate = 0u,
    C8620_AutomaticUpdate = 1u
} c8620_em_cmd_data_update_t;

/*
 * @brief  work mode command
 * @param  0 -> normal work mode
 *         1 -> test work mode
 */
typedef enum
{
    C8620_NormalMode = 0u,
    C8620_TestMode = 1u
} c8620_em_cmd_work_mode_t;

/*
 * @brief  address mode command
 * @param  0 -> automatic address mode
 *         1 -> specify address mode
 */
typedef enum
{
    C8620_AutomaticAddress = 0u,
    C8620_SpecifyAddress = 1u
} c8620_em_cmd_address_mode_t;

/* Address command define -----------------------------------------------------*/
#define CMD_AUTO_START_ADDRESS 0xC0

/* Display command define -----------------------------------------------------*/
/*
 * @brief  set PWM clock
 * @param  0x00 -> 1M
 *         0x01 -> 2M
 *         0x02 -> 4M
 *         0x03 -> 8M
 */
typedef enum
{
    C8620_Clock1M = 0u,
    C8620_Clock2M = 1u,
    C8620_Clock4M = 2u,
    C8620_Clock8M = 3u
} c8620_em_cmd_pwm_clock_t;

/*
 * @brief  display enable
 * @param  0 -> disable
 *         1 -> enable
 */
typedef enum
{
    C8620_Disable = 0u,
    C8620_Enable = 1u
} c8620_em_cmd_display_enable_t;

/*
 * @brief  eliminate the ghosting
 * @param  0 -> slight
 *         1 -> strong
 */
typedef enum
{
    C8620_Slight = 0u,
    C8620_Strong = 1u
} c8620_em_cmd_ghost_reduction_t;

/*
 * @brief  row scan time
 * @param  0x00 -> 4 pwm cycle
 *         0x01 -> 8 pwm cycle
 *         0x02 -> 12 pwm cycle
 *         0x03 -> 16 pwm cycle
 */
typedef enum
{
    C8620_PwmCycle4 = 0u,
    C8620_PwmCycle8 = 1u,
    C8620_PwmCycle12 = 2u,
    C8620_PwmCycle16 = 3u
} c8620_em_cmd_row_break_time_t;

/* Ampere command define ------------------------------------------------------*/
/*
 * @brief  current gain
 * @param  0~31 -> 6.75~30mA
 * @note   Iout = 0.75 * (9 + G)
 */
typedef enum
{
    C8620_mA_6_75 = 0,
    C8620_mA_7_5 = 1,
    C8620_mA_8_25 = 2,
    C8620_mA_9 = 3,
    C8620_mA_9_75 = 4,
    C8620_mA_10_5 = 5,
    C8620_mA_11_25 = 6,
    C8620_mA_12 = 7,
    C8620_mA_12_75 = 8,
    C8620_mA_13_5 = 9,
    C8620_mA_14_25 = 10,
    C8620_mA_15 = 11,
    C8620_mA_15_75 = 12,
    C8620_mA_16_5 = 13,
    C8620_mA_17_25 = 14,
    C8620_mA_18 = 15,
    C8620_mA_18_75 = 16,
    C8620_mA_19_5 = 17,
    C8620_mA_20_25 = 18,
    C8620_mA_21 = 19,
    C8620_mA_21_75 = 20,
    C8620_mA_22_5 = 21,
    C8620_mA_23_25 = 22,
    C8620_mA_24 = 23,
    C8620_mA_24_75 = 24,
    C8620_mA_25_5 = 25,
    C8620_mA_26_25 = 26,
    C8620_mA_27 = 27,
    C8620_mA_27_75 = 28,
    C8620_mA_28_5 = 29,
    C8620_mA_29_25 = 30,
    C8620_mA_30 = 31
} c8620_em_cmd_current_gain_t;

/* Exported variables ---------------------------------------------------------*/
typedef struct
{
    c8620_em_cmd_row_scan_t emRowScan;
    c8620_em_cmd_data_update_t emDataUpdata;
    c8620_em_cmd_work_mode_t emWorkMode;
    c8620_em_cmd_address_mode_t emAddressMode;
    c8620_em_cmd_pwm_clock_t emPwmClock;
    c8620_em_cmd_display_enable_t emDisplay;
    c8620_em_cmd_ghost_reduction_t emGhostReduction;
    c8620_em_cmd_row_break_time_t emRowBreakTime;
    c8620_em_cmd_current_gain_t emCurrentGain;
} c8620_ty_cmd_config_t;

typedef struct
{
    unsigned char Mode;
    unsigned char Display;
    unsigned char Current;
} c8620_ty_cmd_setting_t;
typedef struct
{
    unsigned char SEG[8];

} s_segx_t;
typedef struct
{
    s_segx_t COM[8];
} s_c8620_com_seg_t;
/* display variable */
extern Ram unsigned char C8620_DisplayBuf[C8620_BUF_SIZE];
extern CONST unsigned char c8620_BreathGamma[C8620_BREATH_SZIE];
/* config variable */
extern Ram c8620_ty_cmd_config_t c8620_tCmdConfig;
extern Ram c8620_ty_cmd_setting_t c8620_tCmdSetting;

/* Exported functions ---------------------------------------------------------*/
extern void Dev_C8620_Init(void);
extern void Dev_C8620_SendAddrMode(unsigned char addr, unsigned char sdata);
extern void Dev_C8620_DisplaySetCurrent(unsigned char current);
extern void Dev_C8620_DisplayClearBuf(void);
extern void Dev_C8620_DisplaySequAll(unsigned char lumi);
extern void Dev_C8620_DisplaySequBuf(void);
extern unsigned char Dev_C8620_DisplayBreathBuf(void);
extern unsigned char *Dev_C8620_DisplayMarqueeBuf(void);
void Dev_C8620_Scan(void);
#endif /* __C8620_H__ */
#endif